package com.j180.excepetion;


import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;


@ControllerAdvice
public class MyExceptionHandlerAdvice {

    @ExceptionHandler(MyException.class)
    public ModelAndView handlerException(MyException myException){

        System.out.println("发生异常时,处理异常");
        ModelAndView modelAndView = new ModelAndView();

        modelAndView.addObject("msg",myException.showError());

        modelAndView.setViewName("error");

        return modelAndView;
    }


    @ExceptionHandler(NumException.class)
    public String  handlerNumException(NumException e, Model m){

        System.out.println("发生异常"+e.showInfo());

        m.addAttribute("msg",e.showInfo());

        return "error";
    }




}
